package com.atguigu.customer.demo.controller;


import com.atguigu.customer.demo.bean.Customer;
import com.atguigu.customer.demo.service.CustomerService;
import com.atguigu.customer.demo.service.impl.CustomerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class CustomerController {

    @Autowired
    CustomerService customerService;

    @RequestMapping("/sayhello")
    public String sayhello(){
      return  "hello ! ";
    }
    //参数  1  键值对参数  /xxx/xxx?a=xx&b=xxx&c=axx   条件 附加参数

   // @RequestMapping(value = "/customer"  ,method = RequestMethod.GET)
    @GetMapping("/customer")
    public String getCustomerList(@RequestParam("name") String name , @RequestParam(value = "age",required = false  ,defaultValue = "0") Integer age){

        return "查询用户：名称："+name+"年龄 :"+age;
    }

    // 参数： 2  路径中的参数  /xxxx/1234           主键 唯一标识
    @GetMapping("/customer/{id}.html")
    public String getCustomerById( @PathVariable("id") String id ){
       // String name=null;
       // System.out.println(name.toString());
        return "查询用户：id："+id;
    }


    // 写操作
   // @RequestMapping(value ="/customer" ,method = RequestMethod.POST)
    @PostMapping("/customer")
    public String  saveCustomer(@RequestBody  Customer customer){

        customerService.saveCustomer(customer);
        return  "success";

    }


}
